package main;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.Border;

import main.bots.Methods;
import main.bots.ScriptManager;
import main.constants.Constants;
import main.guis.GUIHelper;
import main.update.UpdateCheck;




@SuppressWarnings("serial")
public class GUI extends JFrame {
	JMenu fileMenu = new JMenu("File");
	JMenuBar mainBar = new JMenuBar();
	JMenuItem serverItem = new JMenuItem("Set Server");
	PaintClass paintClass = new PaintClass();
	JMenu clientMenu = new JMenu("Client");
	JMenu clientSettings = new JMenu("Settings");
	JMenuItem runButton = new JMenuItem("Run");
	
	JMenuItem proxyButton = new JMenuItem("Proxy");
	
	JMenu scriptMenu = new JMenu("Script");
	JMenuItem startItem = new JMenuItem("Start Script");
	JMenuItem stopItem = new JMenuItem("Stop Script");
	
	public static GUI toUse;
	public client getClients() {
		return Methods.getClientToUse();
	}
	public GUI getGUI() {
		return toUse;
	}
	public GUI() {
		toUse = this;
		if(UpdateCheck.updateAvailible())
		JOptionPane.showMessageDialog(this,"New Update Availible! www.coder-austin.com/forums", "Check for updates", 0);
		setDefaultCloseOperation(HIDE_ON_CLOSE);
		paintClass.setSize(300, 300);
		serverItem.addActionListener(new ActionListener() {
			
			@SuppressWarnings("deprecation")
			@Override
			public void actionPerformed(ActionEvent e) {
				GUIHelper.showGUI("server");
				
		
			}
		});
		
	startItem.addActionListener(new ActionListener() {
			
			@SuppressWarnings("deprecation")
			@Override
			public void actionPerformed(ActionEvent e) {
				GUIHelper.showGUI("startscript");
				
		
			}
		});
	
	proxyButton.addActionListener(new ActionListener() {
		
		@SuppressWarnings("deprecation")
		@Override
		public void actionPerformed(ActionEvent e) {
			GUIHelper.showGUI("proxyswitcher");
			
	
		}
	});
	
	stopItem.addActionListener(new ActionListener() {
		
		@SuppressWarnings("deprecation")
		@Override
		public void actionPerformed(ActionEvent e) {
			ScriptManager.stopCurrentScript();
			
			
	
		}
	});
	
	
	//add(mainBar);
	mainBar.add(fileMenu);
	
	fileMenu.add(serverItem);
	
	
	mainBar.add(scriptMenu);
	
	scriptMenu.add(startItem);
	scriptMenu.add(stopItem);
	
	mainBar.add(clientMenu);
	clientMenu.add(clientSettings);
	
	clientMenu.add(proxyButton);
	
	clientSettings.add(runButton);
	setJMenuBar(mainBar);
	getContentPane().add(paintClass, BorderLayout.CENTER);
	

	
	
		
			
			
			
			
		
			
		
			
			
			
			setSize(Constants.GUI_WIDTH_X, Constants.GUI_WIDTH_Y);
			setVisible(Constants.GUI_ENABLED);
			setResizable(Constants.GUI_RESIZABLE);
			toFront();
			pack();
			System.out.println("finished");
		
}
	
	public Canvas getCanvasToPaint() {
		return paintClass;
	}
	
	
}